//初始化
mui.init();
var mask = mui.createMask(); //遮罩层
//获取本地储存数据
var my_phone = localStorage.getItem("my_phone");
var user_id = localStorage.getItem("user_id");
var is_realname, pay_password, description;
var status = 0; //修改手机号审核状态
//返回user页面
$(document).on('tap', '.go_user', function() {
	window.top.location.href = "my_user.html";
})
var uid;
//我的二维码
document.getElementById("code-detail").addEventListener("tap", function() {
	mui.openWindow({
		url: '../my/team-detail.html',
		createNew: true,
		extras: {
			uid: uid
		},
	});
});

//userinfo接口调用
function userinfo() {
	mui.ajax(user_url + '/api/user/getuserInfo', {
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		success: function(data) {
			console.log(JSON.stringify(data))
			if(data.code == 10000) {
				description = data.resp.description;         //实名认证驳回原因				
				$("#user_phone").text(data.resp.user_tel);
			}
		},
		error: function(xhr, type, errorThrown) { //异常处理；
			console.log(type);
		}
	});
}

//我的团队
function teamList() {
	mui.ajax(user_url + '/api/user/getgroup', {
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		success: function(data) {
			console.log(JSON.stringify(data))
			if(data.code == 10000) {
				description = data.resp.description; //实名认证驳回原因
				$(".account_span i").text(data.resp.sum_silver_treasure);
				uid = data.resp.uid;
				var html = ""
				
				if(data.resp.subordinate!=null){
					var hotShop = data.resp.subordinate;
					for(var i = 0; i < hotShop.length; i++) {					
						html += '<div class="mui-input-row account_phone_row team-li">'
						html += '<img width="100%" class="team-img" src="../../images/user-icon.png"/>'
						html += '<div class="team-le">'
						html += '<p>'+hotShop[i].user_tel+'</p>'
						html += '</div>'
						html += '<div class="team-ri">'+hotShop[i].silver_treasure+'银宝</div>'
						html += '</div>';
					}
					$(".team-li-box").html(html);
				}				
				
			}
		},
		error: function(xhr, type, errorThrown) { //异常处理；
			console.log(type);
		}
	});
}




//页面进入执行方法
window.onload = function() {
	mui.plusReady(function() {
		//self = plus.webview.currentWebview();
//		userinfo(); //用户接口方法
		teamList();
		plus.nativeUI.closeWaiting(); //关闭等待
		mask.close(); //关闭遮罩层
		//页面刷新
		window.addEventListener('refresh_method', function(e) { //执行刷新
			location.reload();
		});
	});
}